/**
 * @param {string} s
 * @param {number} k
 * @return {string}
 */
var reverseStr = function (s, k) {
    let sLen = s.length,
        sArr = Array.from(s),
        left,
        right
    for (let i = 0; i < sLen; i += 2 * k) {
        left = i
        right = Math.min(sLen, i + k) - 1
        while (left < right) {
            let temp = sArr[left];
            sArr[left] = sArr[right];
            sArr[right] = temp;
            left++;
            right--;
        }
    }
    return sArr.join('')
};

console.log(reverseStr("abcdefga", 3))